package com.ai.nsa.processor;

import com.ai.nsa.NSAInputers;
import com.ai.nsa.utils.MapTools;
import com.alibaba.fastjson.JSON;
import com.asiainfo.its.ITSProcessor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.ai.nsa.NSAConstants.COLUMN_INTERACT_TYPE;
import static com.ai.nsa.NSAConstants.COLUMN_SERIAL_NUMBER;

/**
 * @author Feng Chen 2017/6/8.
 */
@Component(value = "nSAProcessor")
public class NSAProcessor implements ITSProcessor {

    @Autowired
    private NSAInputers inputers;

    @Override
    public void process(String event) throws Exception {
        Map<String, Object> data = JSON.parseObject(event);
        String serialNumber = MapTools.getString(data, COLUMN_SERIAL_NUMBER);
        String interact = MapTools.getString(data, COLUMN_INTERACT_TYPE);

        if (StringUtils.isEmpty(serialNumber) || StringUtils.isEmpty(interact)) {
            return;
        }

        inputers.get(interact).put(data);

    }

}
